import { defineMongooseModel } from "#nuxt/mongoose";
export interface UserDataProps {
  account: string;
  password: string;
  avatar: string;
  gender: string;
  name: string;
  nickName: string;
  age: number;
  createdAt: string;
  updatedAt: string;
  address: string;
  roles: string[];
  department: string;
  positions: string[];
  disabled?: boolean;
}
export const UserSchema = defineMongooseModel<UserDataProps>(
  "User",
  {
    account: { type: String, unique: true, required: true },
    avatar: { type: String },
    gender: { type: String },
    age: { type: Number, min: 0, max: 160 },
    password: { type: String, required: true },
    name: { type: String },
    nickName: { type: String },
    address: { type: String },
    disabled: { type: Boolean },
    roles: { type: [String] },
    department: { type: String },
    positions: { type: [String] },
  },
  {
    timestamps: true,
    toJSON: {
      // 过滤掉敏感字段
      transform(doc: any, ret: Record<string, any>, options: any) {
        delete ret.__v;
        delete ret.password;
      },
    },
  }
);
